package com.bjc.principle.liskov;

/**
 * @program: DesignPattern
 * @description: 里氏替换原则
 * @author: bjc
 * @create: 2020-12-13 16:58
 */
public class Liskov {
    public static void main(String[] args) {
        A a = new A();
        System.out.println("11-3="+a.func1(11,3));
        System.out.println("1-8="+a.func1(1,8));
        System.out.println("---------------------");
        B b = new B();
        System.out.println("11-3="+b.func1(11,3));
        System.out.println("1-8="+b.func1(1,8));
        System.out.println("11+3+9="+b.func1(11,3));
    }
}
//A类
class A{
    //返回两个数的差
    public int func1(int num1,int num2){
        return num1-num2;
    }
}
//B类
//增加了一个新功能：完成两个数相加再和9相加
class B extends A{
    //这里重写了A类方法，可能是无意识的
    public int func1(int num1,int num2){
        return num1+num2;
    }
    public int func2(int num1,int num2){
        return func1(num1,num2)+9;
    }
}
